Public Partial Class Photos
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Sub Button1_Click(ByVal sender As Object, ByVal e As ImageClickEventArgs)
        Dim d As IO.DirectoryInfo = New IO.DirectoryInfo(Server.MapPath("~/Upload"))
        Dim enumerator As System.Collections.IEnumerator = CType(d.GetFiles("*.jpg"), System.Collections.IEnumerable).GetEnumerator
        Do While enumerator.MoveNext
            Dim f As IO.FileInfo = CType(enumerator.Current, IO.FileInfo)
            Dim buffer() As Byte = New Byte((f.OpenRead.Length) - 1) {}
            f.OpenRead.Read(buffer, 0, CType(f.OpenRead.Length, Integer))
            KDESolutions.Providers.Images.ImageService.AddPhoto(Request.QueryString("AlbumID"), f.Name, buffer, HttpContext.Current.User.Identity.Name)
        Loop
        GridView1.DataBind()
    End Sub

    Public Sub FormView1_ItemInserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewInsertEventArgs) Handles FormView1.ItemInserting
        If (CType(e.Values("BytesOriginal"), [Byte]()).Length = 0) Then
            e.Cancel = True
        End If
    End Sub

    Private Sub ObjectDataSource1_Deleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ObjectDataSourceMethodEventArgs) Handles ObjectDataSource1.Deleting
        e.InputParameters("Username") = HttpContext.Current.User.Identity.Name
    End Sub

    Private Sub ObjectDataSource1_Inserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ObjectDataSourceMethodEventArgs) Handles ObjectDataSource1.Inserting
        e.InputParameters("Username") = HttpContext.Current.User.Identity.Name
    End Sub

    Private Sub ObjectDataSource1_Updating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ObjectDataSourceMethodEventArgs) Handles ObjectDataSource1.Updating
        e.InputParameters("Username") = HttpContext.Current.User.Identity.Name
    End Sub
End Class